﻿using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using UpperComputer.Base.Core.Locators;
using YFurion.Entities;

namespace UpperComputer.Base.Core.Entities
{
    public class DataDictionary : CMEntity<BaseMasterDbContextLocator, BaseSlaveDbContextLocator>, IEntityTypeBuilder<DataDictionary, BaseMasterDbContextLocator, BaseSlaveDbContextLocator>
    {
        public string Code { get; set; }

        public string DisplayName { get; set; }

        public string Value { get; set; }

        public string ParentCode { get; set; }

        public int Sort { get; set; }

        public void Configure(EntityTypeBuilder<DataDictionary> entity, DbContext dbContext, Type dbContextLocator)
        {
            entity.HasIndex(e => e.Code, "UQ__DataDictionary")
            .IsUnique();

            entity.Property(e => e.Id)
                 .ValueGeneratedNever();

            entity.Property(e => e.Code)
                .IsRequired()
                .HasMaxLength(50)
                .IsUnicode(false);

            entity.Property(e => e.DisplayName)
                .IsRequired()
                .HasMaxLength(50);

            entity.Property(e => e.Value)
                .HasMaxLength(50);

            entity.Property(e => e.ParentCode)
                .HasMaxLength(50)
                .IsUnicode(false);
        }
    }
}
